package com.honweek;

public class Deom5 {
    public static void main(String[] args) {
         //创建线程任务对象
        Ticket ticket = new Ticket();
        //创建三个窗口对象
        Thread t1 = new Thread(ticket,"窗口1");
        Thread t2 = new Thread(ticket,"窗口2");
        Thread t3 = new Thread(ticket,"窗口3");
        t1.start();
        t2.start();
        t3.start();
    }
}

class Ticket implements Runnable {
    private int ticket = 100;

    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                if (ticket >= 0) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    String name= Thread.currentThread().getName();
                    System.out.println(name+"正在热卖，还剩：" + ticket-- + "张票");
                }
            }
        }
    }
}